//
//  MainViewController.m
//  CreditManager
//
//  Created by zhl on 2017/8/9.
//  Copyright © 2017年 zhl. All rights reserved.
//

#import "MainViewController.h"

@interface MainViewController ()<UITabBarControllerDelegate>

@end

@implementation MainViewController



//动态更新状态栏颜色
-(void)setStatusBarStyle:(UIStatusBarStyle)StatusBarStyle{
    _StatusBarStyle = StatusBarStyle;
    [UIApplication sharedApplication].statusBarStyle = StatusBarStyle;
    [self setNeedsStatusBarAppearanceUpdate];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kColor(245, 245, 245);
    
    
//    self.fd_prefersNavigationBarHidden = YES;

}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [Tool showNoNetwork:self];//检查网络
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}


- (void)setNavigationBarHidden:(BOOL)isHidden StatusBarStyle:(UIStatusBarStyle)StatusBarStyle barTintColor:(UIColor *)barTintColor{
    self.navigationController.navigationBarHidden = isHidden;
    self.StatusBarStyle = StatusBarStyle;

    self.navigationController.navigationBar.barTintColor = barTintColor;
}


- (void)showMaskView:(UIView *)maskView{
    maskView.hidden = NO;
}

- (void)remvoeMaskView:(UIView *)maskView{
    maskView.hidden = YES;
    
}


/** HUD展示*/
- (void)hudShowWithViewController:(UIViewController *)vc isHidden:(BOOL)isHidden{
    
    if (self.hud.alpha == 0 || self.hud == nil) {
        self.hud = nil;
        self.hud = [MBProgressHUD showHUDAddedTo:vc.navigationController.view animated:YES];
    }
    if (isHidden) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self hudClose];
        });
    }
}

/** HUD带字展示*/
- (void)hudShowWithWithViewController:(UIViewController *)vc Title:(NSString *)title isHidden:(BOOL)isHidden{
    
    if (self.hud.alpha == 0 || self.hud == nil) {
        self.hud = nil;
        if (vc.navigationController != nil) {
            self.hud = [MBProgressHUD showHUDAddedTo:vc.navigationController.view animated:YES];
        } else {
            self.hud = [MBProgressHUD showHUDAddedTo:vc.view animated:YES];
        }
        
    }
    self.hud.labelText = title;
    if (isHidden) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self hudClose];
        });
    }
}

/** HUD消失*/
- (void)hudClose{
    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.hud hide:YES afterDelay:1];
            
        });
    });
}

/** Alert展示消息*/
-(void)showAlert:(NSString*)alertStr{
  
    UIAlertController *alert = [UIAlertController
                                alertControllerWithTitle:@"提示"
                                message:alertStr
                                preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"知道了"
                                              style:UIAlertActionStyleDefault
                                            handler:nil]
     ];
    
    [self presentViewController:alert animated:YES completion:nil];
    [self hudClose];
}


- (void)alertWithTitle:(NSString *)title message:(NSString *)message Completion:(void (^)(void))completion{
    UIAlertController *alert = [UIAlertController
                                alertControllerWithTitle:title
                                message:message
                                preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消"
                                              style:UIAlertActionStyleCancel
                                            handler:nil]
     ];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定"
                                              style:UIAlertActionStyleDefault
                                            handler:^(UIAlertAction *
_Nonnull action) {
                                                completion();
                                            }]
     ];
    [self presentViewController:alert animated:YES completion:nil];
    
}


@end
